//
// Created by lizhehao on 2/19/21.
//

#ifndef ROBOWALKER_CAMERA_H
#define ROBOWALKER_CAMERA_H

#include <memory.h>
#include "opencv2/opencv.hpp"
#include <cstdio>
#include <cstdlib>
#include <string>
#include "hikvision_camera_api/MvCameraControl.h"

using namespace cv;
using namespace std;

namespace robowalker {

    typedef struct CameraParams
    {
        Mat cameraMatrix;
        Mat distCoeffs;
    }CameraParams;

    class Camera {
    public:
        Camera(const string& paramFilePath, const double expectedFrameRate=90.0, const int exposureTime=10000,
               const int imgHeight=1024, const int imgWidth=1280);
        ~Camera();

        bool is_open() const;
        void* getCameraHandle() const;
        float getCurrentFrameRate() const;

        cv::Mat* readOneFrame(Mat& output, int64_t & TimeStamp);

        pair<double, double> getAngle(const Point2f center) const;
        Point2f getPixelSize(float angleX, float angleY) const;
        double getDistance(const int armorBoxType, const Point2f*) const;

    private:
        int nBuffSize;
        unsigned char* pFrameBuf;
        MV_FRAME_OUT_INFO_EX stInfo;
        void* cameraHandle;

        bool is_opened;

        CameraParams params;
    };
}


#endif //ROBOWALKER_CAMERA_H
